import datetime
from settings.publicvar import Base
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy import  ForeignKey
from typing_extensions import Annotated

from views.schoolInfo.model.SchoolInfo import SchoolInfo

int_pk = Annotated[int,mapped_column(primary_key=True)]

class Author(Base):
    __tablename__ = 'author'

    id:Mapped[int_pk]
    name:Mapped[str]

class Publisher(Base):
    __tablename__ = 'publisher'

    id: Mapped[int_pk]
    name:Mapped[str]
    website:Mapped[str] = mapped_column(nullable=True)
    description:Mapped[str] = mapped_column(nullable=True)

class Category(Base):
    __tablename__ = 'category'

    id: Mapped[int_pk]
    name:Mapped[str]
    description:Mapped[str] = mapped_column(nullable=True)

class Books(Base):
    __tablename__ = 'books'

    id: Mapped[int_pk]
    school_id:Mapped[int] = mapped_column(ForeignKey('schoolinfo.id'),nullable=True)
    isbn:Mapped[str]
    title:Mapped[str]
    author_id:Mapped[int] = mapped_column(ForeignKey('author.id'),nullable=True)
    publisher_id:Mapped[int] = mapped_column(ForeignKey('publisher.id'),nullable=True)
    publish_date:Mapped[datetime.date] = mapped_column(nullable=True)
    summary:Mapped[str] = mapped_column(nullable=True)
    price:Mapped[float]
    amount:Mapped[int]
    category_id:Mapped[int] = mapped_column(ForeignKey('category.id'),nullable=True)
    create_date:Mapped[datetime.date] = mapped_column(nullable=True)
    update_date:Mapped[datetime.date] = mapped_column(nullable=True)
    mark:Mapped[str] = mapped_column(nullable=True)

    author: Mapped[Author] = relationship(lazy=False, backref='books_author')
    publisher:Mapped[Publisher] = relationship(lazy=False,backref='books_publisher')
    category:Mapped[Category] = relationship(lazy=False,backref='books_category')
    school:Mapped[SchoolInfo] = relationship(lazy=False,backref='books_school')
